package com.ycsj.goldmedalnewconcept.teacher.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ycsj.common.base.BaseActivity;
import com.ycsj.common.base.BaseApplication;
import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.common.HttpAddress;

/**
 * 习题分析图表H5界面
 * Created by Administrator on 2018/10/22 0022.
 */
public class TeacherH5AppraisalTestPaperActivity extends BaseActivity implements View.OnClickListener {

    private ImageView ivBack;

    //标题名称
    private TextView tvTitle;

    private RelativeLayout rlLoading;


    private String school_id;
    private String ttel;
    private String classnum;
    private String total;
    private String unit;
    private WebView webView;

    /**
     * 跳转到当前Activity的方法
     *
     * @return
     */
    public static void startActivity(Context context, String school_id, String ttel,
                                     String classnum, String unit, String total) {
        Intent intent = new Intent(BaseApplication.context, TeacherH5AppraisalTestPaperActivity.class);
        intent.putExtra("school_id", school_id);
        intent.putExtra("ttel", ttel);
        intent.putExtra("classnum", classnum);
        intent.putExtra("unit", unit);
        intent.putExtra("total", total);
        context.startActivity(intent);
    }


    @Override
    protected int getContentLayout() {
        return R.layout.activity_teacher_h5_test_paper;
    }

    @Override
    protected void init() {

        //通知栏沉浸式
        initStateBar();

        //初始化视图
        initView();

        //获取传递参数
        initIntent();

        //初始化标题栏
        initTitle();

        //设置H5界面
        initWebview();

    }

    private void initWebview() {
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setBuiltInZoomControls(false);
        webView.getSettings().setUseWideViewPort(true);
        webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
        webView.getSettings().setDatabaseEnabled(true);
        webView.getSettings().setDomStorageEnabled(true);
        webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
        webView.getSettings().setPluginState(WebSettings.PluginState.ON);
        webView.loadData("", "text/html", null);
        webView.getSettings().setPluginState(WebSettings.PluginState.ON);

        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
                view.loadUrl(url);
                return true;
            }
        });
        webView.loadUrl(HttpAddress.UPDATE_URL + "JPXB/sharePage/pages/JPXB/xinerShare/TestShareNew.html?type=2&" +
                "school_id=" + school_id + "&ttel=" + ttel + "&classnum=" + classnum + "&unit=" + unit + "&total=" + total + "&platform=5");
    }


    /**
     * 初始化标题栏
     */
    private void initTitle() {
        tvTitle.setText("Unit" + unit + "习题分析");
    }

    /**
     * 获取传递参数
     */
    private void initIntent() {
        Intent intent = getIntent();
        school_id = intent.getStringExtra("school_id");
        ttel = intent.getStringExtra("ttel");
        classnum = intent.getStringExtra("classnum");
        unit = intent.getStringExtra("unit");
        total = intent.getStringExtra("total");
    }


    /**
     * 初始化视图
     */
    public void initView() {
        ivBack = findViewById(R.id.iv_back);
        webView = findViewById(R.id.webview);
        ivBack.setOnClickListener(this);
        tvTitle = findViewById(R.id.tv_title);
        rlLoading = findViewById(R.id.rl_loading);
        rlLoading.setVisibility(View.GONE);

    }


    /**
     * 点击事件
     *
     * @param v
     */
    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.iv_back) {
            //返回
            finish();
        }
    }
}
